package cn.zhaoyuening.zhaocloud.provider.core.impl;

import java.util.TreeSet;

import cn.zhaoyuening.zhaocloud.common.bean.CloudServiceBean;
import cn.zhaoyuening.zhaocloud.common.bean.CloudServiceRegisterBean;
import cn.zhaoyuening.zhaocloud.provider.core.CloudServiceProvider;
import cn.zhaoyuening.zhaocloud.provider.listener.CloudServiceCallListener;
import cn.zhaoyuening.zhaocloud.provider.register.CloudServiceRegister;
import cn.zhaoyuening.zhaocloud.provider.register.impl.BaseCloudServiceRegister;

/**
 * 依赖与Spring IOC容器的 CloudServiceProvider 实现
 * @author 赵岳宁
 *
 */
public class BaseCloudServiceProvider implements CloudServiceProvider{
	//服务暴露端口
	private Integer port;
	//服务注册器，负责与注册中心进行交互
	private CloudServiceRegister serviceRegister;
	//远程请求服务监听器，监听外来服务
	private CloudServiceCallListener requestListener;
	private String registryHost;
	private Integer registryPort; 
	
	public BaseCloudServiceProvider(){
		serviceRegister = new BaseCloudServiceRegister(port, registryHost, registryPort);
	}
	
	//必须使用TreeSet
	public void publishService(TreeSet<CloudServiceBean> serviceSet) {
		//将服务发布端口以及服务列表封装，交友register注册器通知注册中心进行服务的注册
		CloudServiceRegisterBean registerBean = new CloudServiceRegisterBean(port,serviceSet);
		serviceRegister.registryService(serviceSet);
		//开始监听服务的请求
		requestListener.startListener(serviceSet);
	}


	
	
	
	public void setPort(Integer port) {
		this.port = port;
	}

	public void setServiceRegister(CloudServiceRegister serviceRegister) {
		this.serviceRegister = serviceRegister;
	}

	public void setRequestListener(CloudServiceCallListener requestListener) {
		this.requestListener = requestListener;
	}

	public String getRegistryHost() {
		return registryHost;
	}

	public void setRegistryHost(String registryHost) {
		this.registryHost = registryHost;
	}

	public Integer getRegistryPort() {
		return registryPort;
	}

	public void setRegistryPort(Integer registryPort) {
		this.registryPort = registryPort;
	}

	public Integer getPort() {
		return port;
	}

	public CloudServiceRegister getServiceRegister() {
		return serviceRegister;
	}

	public CloudServiceCallListener getRequestListener() {
		return requestListener;
	}
	
	
	

}
